package com.szcinda.fitness.security;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Data
@NoArgsConstructor
public class AuthenticatedUser implements UserDetails {

    private String id;
    private String username;
    private String name;
    private String password;
    private String organization;
    private String currentOrganization;
    private String rootOrganizationId;
    private List<String> roles;
    private Set<? extends GrantedAuthority> authorities = new HashSet<>();
    private boolean locked = false;

    public boolean isAdmin(){
        if(roles==null){
            return false;
        }else if(roles.contains("ROLE_SUPER_ADMIN")){
            return true;
        }
        return false;
    }

    @Override
    public boolean isAccountNonExpired() {
        return !locked;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !locked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return !locked;
    }

    @Override
    public boolean isEnabled() {
        return !locked;
    }
}
